package cn.circle.system.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import cn.circle.commom.dao.impl.BaseDaoImpl;
import cn.circle.system.util.PageHelper;
import cn.circle.system.dao.ISysCustomerDao;
import com.graduation.system.model.SysCustomer;

@Repository
public class SysCustomerDao extends BaseDaoImpl<SysCustomer> implements ISysCustomerDao {

	@SuppressWarnings("unchecked")
	public List<SysCustomer> datagrid() {
		// TODO Auto-generated method stub
		String hql = "from SysCustomer ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return query.list();
	}

	public List<SysCustomer> getUser(String id) {
		// TODO Auto-generated method stub
		
		String hql = "from SysCustomer where custId = '"+id+"'";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return query.list();
	}

	public boolean updataAll(SysCustomer c){
		StringBuffer hql = new StringBuffer(
				"update SysCustomer s set ");
		
		//拼接修改条件
		if(c.getUserName() != null && !"".equals(c.getUserName())){
			hql.append("  s.userName = '"+c.getUserName()+"' ");
		}
		if(c.getStatus() != null && !"".equals(c.getStatus())){
			hql.append(" , s.status = '"+c.getStatus()+"' ");
		}

		if(c.getPassWord() != null && !"".equals(c.getPassWord())){
			hql.append(" , s.passWord = '"+c.getPassWord()+"' ");
		}
		if(c.getSysDepartment().getDepId() != null && !"".equals(c.getSysDepartment().getDepId())){
			hql.append(" , s.sysDepartment.depId = "+c.getSysDepartment().getDepId()+" ");
		}
		if(c.getPhone() != null && !"".equals(c.getPhone())){
			hql.append(" , s.phone = "+c.getPhone()+" ");
		}

		hql.append(" where s.custId ="+c.getCustId()+" ");
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql.toString());
		return (query.executeUpdate() > 0);
		
	}
	public boolean deleteAll(String custIds) {
		// TODO Auto-generated method stub
		String hql = "delete SysCustomer s where s.custId in ("+custIds+") ";
		System.out.println(hql);
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return (query.executeUpdate() > 0);
	}

}
